layui.use(['form','jquery'],function () {
    var form = layui.form,
        $ = layui.jquery;


    /**
     *添加用户
     */
    form.on("submit(addConsumer)",function(data) {
        var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        var obj = data.field;
        console.log(obj)
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/consumerController/add',
            data: JSON.stringify(obj),
            dataType: 'json',
            contentType: 'application/json',
            success: function (data) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg(data.msg);
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });

    /**
     *修改用户
     */
    form.on("submit(updateConsumer)",function(data) {
        var index = top.layer.msg('数据修改中，请稍候', {icon: 16, time: false, shade: 0.8});
        var obj = data.field;
        console.log(obj)
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/consumerController/update',
            data: JSON.stringify(obj),
            dataType: 'json',
            contentType: 'application/json',
            success: function (data) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg(data.msg);
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });


    /**
     * 添加维修员
     */
    form.on("submit(addRepair)",function(obj) {
        var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        var data = obj.field;
        console.log(data)
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/servicemanController/add',
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json',
            success: function (res) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });

    /**
     * 修改维修员
     */
    form.on("submit(updateRepair)",function(obj) {
        var index = top.layer.msg('数据修改中，请稍候', {icon: 16, time: false, shade: 0.8});
        var data = obj.field;
        console.log(data)
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/servicemanController/update',
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json',
            success: function (res) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });

    /**
     * 添加管理员
     */
    form.on("submit(addAdmin)",function(obj) {
        var index = top.layer.msg('数据提交中，请稍候', {icon: 16, time: false, shade: 0.8});
        var data = obj.field;
        console.log(data)
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/superuserController/add',
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json',
            success: function (res) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });

    /**
     * 修改管理员
     */
    form.on("submit(updateAdmin)",function(obj) {
        var index = top.layer.msg('数据修改中，请稍候', {icon: 16, time: false, shade: 0.8});
        var data = obj.field;
        console.log(data)
        /**
         * 请求后台
         */
        $.ajax({
            type: 'POST',
            url: '/superuserController/update',
            data: JSON.stringify(data),
            dataType: 'json',
            contentType: 'application/json',
            success: function (res) {
                /**
                 * 添加成功后回调
                 **/
                setTimeout(function () {
                    top.layer.close(index);
                    top.layer.msg(res.msg);
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                }, 500);
                return false;
            }
        });
    });
});